h = input()
prob = 0
for k in range(len(h)):
    if h[k] == " ":
        prob +=1
if prob!=2:
    print("Wrong input")
else:
    a, b, c = h.split()
    m = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    if a in m and b in m and c in m and a!='zero':
        num = m.index(a) * 100 + m.index(b) * 10 + m.index(c)
        def pr (n):
            fl = True
            for i in range(2, n):
                if n % i == 0:
                    fl = False
                    break
            return fl

        if pr(num)==True:
            print(num)
        else:
            x = y = 0
            for r in range(num+1, 1100):
                if pr(r) == True:
                    x = r
                    break
            for j in range(num-1, 0, -1):
                if pr(j)==True:
                    y = j
                    break
            if (x-num) < (num-y):
                print(x)
            elif (x-num) > (num-y):
                print(y)
            elif (x-num) == (num-y):
                print(y)
            elif num<100:
                print("Wrong input")

    else:
        print('Wrong input')
